#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/3/4
# @Author: Sunny
# ========================
from multiprocessing import Process
import os

n = 100


def work1():
    global n
    for i in range(500000):
        n += 1
    print(f'进程{os.getpid()}work1执行完毕：{n}')
    print(f'子进程的父进程id:{os.getppid()}')  #可以查看这个子进程是由哪个主进程创建的


def work2():
    global n
    for i in range(500):
        n += 1
    print(f'进程{os.getpid()}work2执行完毕：{n}')


if __name__ == '__main__':
    p1 = Process(target=work1, )
    p2 = Process(target=work2, )

    p1.start()
    p2.start()

    p1.join()
    p2.join()

    print('两个子进程执行结束之后，主进程打印的n：', n)
    print(f'主进程获取id:{os.getpid()}')